package com.tentative.competition.web.controller.schedule.client;

import com.tentative.competition.common.annotation.Anonymous;
import com.tentative.competition.common.constant.Constants;
import com.tentative.competition.common.core.domain.AjaxResult;
import com.tentative.competition.common.model.schedule.param.LoginParam;
import com.tentative.competition.common.utils.uuid.UUID;
import com.tentative.competition.framework.web.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther: Smile Huang
 * @date: 2023/6/21 23:36
 * @desc:
 * @version: 2.0
 */
@Api(tags = "client-登录接口")
@RestController
@RequestMapping("/client")
public class ClientLoginController {

    @Autowired
    private SysLoginService sysLoginService;

    /**
     * 登录方法
     * @return 结果
     */
    @ApiOperation("登录接口")
    @PostMapping("/login")
    @Anonymous
    public AjaxResult login(@RequestBody LoginParam param) {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = sysLoginService.login(param.getUsername(), param.getPassword(), "", UUID.fastUUID().toString());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    @ApiOperation("修改密码")
    @PostMapping("/edit-password")
    @Anonymous
    public AjaxResult editPassword(@RequestBody LoginParam param) {
        sysLoginService.editPassword(param);
        return AjaxResult.success();
    }
}
